package com.ruoyi.web.controller.business;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.TbVehicleIllegal;
import com.ruoyi.system.service.ITbVehicleIllegalService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 车辆违章Controller
 *
 * @author lxy
 * @date 2024-04-28
 */
@RestController
@RequestMapping("/business/illegal")
public class TbVehicleIllegalController extends BaseController {
    @Autowired
    private ITbVehicleIllegalService tbVehicleIllegalService;

    /**
     * 查询车辆违章列表
     */
    @PreAuthorize("@ss.hasPermi('system:illegal:list')")
    @GetMapping("/list")
    public TableDataInfo list(TbVehicleIllegal tbVehicleIllegal) {
        startPage();
        List<TbVehicleIllegal> list = tbVehicleIllegalService.selectTbVehicleIllegalList(tbVehicleIllegal);
        return getDataTable(list);
    }

    /**
     * 导出车辆违章列表
     */
    @PreAuthorize("@ss.hasPermi('system:illegal:export')")
    @Log(title = "车辆违章", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, TbVehicleIllegal tbVehicleIllegal) {
        List<TbVehicleIllegal> list = tbVehicleIllegalService.selectTbVehicleIllegalList(tbVehicleIllegal);
        ExcelUtil<TbVehicleIllegal> util = new ExcelUtil<TbVehicleIllegal>(TbVehicleIllegal.class);
        util.exportExcel(response, list, "车辆违章数据");
    }

    /**
     * 获取车辆违章详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:illegal:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return success(tbVehicleIllegalService.selectTbVehicleIllegalById(id));
    }

    /**
     * 新增车辆违章
     */
    @PreAuthorize("@ss.hasPermi('system:illegal:add')")
    @Log(title = "车辆违章", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody TbVehicleIllegal tbVehicleIllegal) {
        return toAjax(tbVehicleIllegalService.insertTbVehicleIllegal(tbVehicleIllegal));
    }

    /**
     * 修改车辆违章
     */
    @PreAuthorize("@ss.hasPermi('system:illegal:edit')")
    @Log(title = "车辆违章", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TbVehicleIllegal tbVehicleIllegal) {
        return toAjax(tbVehicleIllegalService.updateTbVehicleIllegal(tbVehicleIllegal));
    }

    /**
     * 删除车辆违章
     */
    @PreAuthorize("@ss.hasPermi('system:illegal:remove')")
    @Log(title = "车辆违章", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(tbVehicleIllegalService.deleteTbVehicleIllegalByIds(ids));
    }
}
